﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#include "MenuItemDefinition.h"
#include "GbmpNew.h"
#include "TransferOwnership.h"
#include "CommandControlDefinition.h"
#include "GbmpFileSystem.h"
#include "FilePath.h"
#include "EnableCompileWarning_The_LAST_IncludeInCpp.h"

using namespace gcmp;

gcmp::MenuItemDefinition::~MenuItemDefinition()
{

}

gcmp::MenuItemDefinition::MenuItemDefinition(const std::wstring& id, const std::wstring& commandId, const std::wstring& caption, const std::wstring& tooltip, const std::wstring& iconPath)
    : m_controlDefine(NEW_AS_OWNER_PTR(CommandControlDefinition, id, caption, tooltip, commandId))
{
    m_iconPath = iconPath == L"" ? iconPath : FilePath::GetAbsolutePath(iconPath, gcmp::FileSystem::GetExeDirPath());
}

std::wstring gcmp::MenuItemDefinition::GetId() const
{
    return m_controlDefine->GetId();
}

std::wstring gcmp::MenuItemDefinition::GetCaption() const
{
    return m_controlDefine->GetCaption();
}

std::wstring gcmp::MenuItemDefinition::GetTooltip() const
{
    return m_controlDefine->GetTooltip();
}

std::wstring gcmp::MenuItemDefinition::GetCommandId() const
{
    return m_controlDefine->GetCommandId();
}

std::wstring gcmp::MenuItemDefinition::GetIconPath() const
{
    return m_iconPath;
}

std::vector<const IMenuItemDefinition* > gcmp::MenuItemDefinition::GetSubMenuItems() const
{
    std::vector<const IMenuItemDefinition* > res;
    for (auto& iter : m_subMenuItems)
    {
        res.push_back(iter.get());
    }
    return res;
}

bool gcmp::MenuItemDefinition::IsVisible() const
{
    return m_controlDefine->IsVisible(); 
}

bool gcmp::MenuItemDefinition::IsEnabled() const
{
    return m_controlDefine->IsEnabled();
}

bool gcmp::MenuItemDefinition::AddSubMenuItem(OwnerPtr<IMenuItemDefinition> pSubMenuItem)
{
    m_subMenuItems.emplace_back(TransferOwnership(pSubMenuItem));
    return true;
}

bool MenuItemDefinition::SetCaption(const std::wstring& caption)
{
    DBG_WARN_AND_RETURN_FALSE_UNLESS(m_controlDefine, L"m_controlDefine为空",L"GDMPLab",L"2024-03-30");
    return m_controlDefine->SetCaption(caption);
}

bool MenuItemDefinition::SetIconPath(const std::wstring& iconPath)
{
    DBG_WARN_AND_RETURN_FALSE_UNLESS(m_controlDefine, L"m_controlDefine为空",L"GDMPLab",L"2024-03-30");
    m_iconPath = iconPath;
    return true;
}

bool MenuItemDefinition::SetTooltip(const std::wstring& tooltip)
{
    DBG_WARN_AND_RETURN_FALSE_UNLESS(m_controlDefine, L"m_controlDefine为空",L"GDMPLab",L"2024-03-30");
    return m_controlDefine->SetTooltip(tooltip);
}

void MenuItemDefinition::SetIsChecked(bool isChecked)
{
    DBG_WARN_AND_RETURN_VOID_UNLESS(m_controlDefine, L"m_controlDefine为空",L"GDMPLab",L"2024-03-30");
    m_controlDefine->SetIsChecked(isChecked);
}

bool MenuItemDefinition::IsChecked() const
{
    DBG_WARN_AND_RETURN_FALSE_UNLESS(m_controlDefine, L"m_controlDefine为空",L"GDMPLab",L"2024-03-30");
    return m_controlDefine->IsChecked();
}

//////////////////////////////////////////////////////////////////////////
// 分割符号定义
SeparatorItemDefinition::SeparatorItemDefinition()
{
}

gcmp::SeparatorItemDefinition::~SeparatorItemDefinition()
{
}
